<?php
namespace API\Controller;
use Think\Controller;
header("Content-type: text/json; charset=utf-8"); 
class NewsController extends Controller {

/*1.获取所有影讯信息*/
public function getNewslist(){
        //调用模型层获取数据
        $newsmodel=M('news');  
        $news=$newsmodel->order('n_time desc')->select();
        echo json_encode($news);
    }


/*2.获取某一条影讯的详情*/
     public function getDetail(){
      $n_id=$_GET['n_id'];
      $newsmodel=M('news');
      $news=$newsmodel->find($n_id); 
      $this->news=$news;
      echo json_encode($news);
    } 

/*3.影讯评论列表*/
 public function getNewsCommentlist()
    {
        $n_id=$_GET['n_id'];
        $flag=$_GET['flag'];
        $commentsmodel=M('comments');
    
       $comments=$commentsmodel->table('vm_comments ct,vm_news p,vm_users u')->where("p.n_id=$n_id and ct.comment_id=p.n_id and ct.u_id=u.u_id and ct.comment_flag=$flag")->order('com_id desc')->field('p.n_id,u.u_id,u.u_name,ct.*')->select();
        echo json_encode($comments);        
    }




    }
    

